<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div id="code-search" style="padding-bottom: 10px;padding-top: 10px">
    <div style="padding-bottom: 10px">
        <span>彩种:</span>
        <input id="lottery-type-add" name="type" editable="false"/>
    </div>

    <div style="padding-bottom: 10px">
        <span>省市:</span>
        <input id="lottery-city-add" name="city" editable="false"/>
    </div>
    <%--    <div style="padding-bottom: 10px">--%>
    <%--        <span>日期:</span>--%>
    <%--        <input id="lottery-date-add" name="date"/>--%>
    <%--    </div>--%>

    <div style="padding-bottom: 10px">
        <span>期号:</span>
        <input type="text" name="issueno" class="easyui-textbox" id="lottery-issueno-add"/>
        <%--        <input id="lottery-issueno-add" name="issueno"/>--%>
        <span>(例如：19080418-)</span>
    </div>

    <div>
        <span>开奖号码:</span>
        <input id="number1" name="number1" style="width:50px;"/>
        <input id="number2" name="number2" style="width:50px;"/>
        <input id="number3" name="number3" style="width:50px;"/>
        <input id="number4" name="number4" style="width:50px;"/>
        <input id="number5" name="number5" style="width:50px;"/>
    </div>

    <div>
        <a id='lottery-add' class="easyui-linkbutton" iconCls="icon-add">添加</a>
    </div>

</div>
<script type="text/javascript">
    function getFormatDate() {
        var nowDate = new Date();
        var year = nowDate.getFullYear();
        var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
        var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
        var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
        var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
        var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    }

    $(function () {
        $('#lottery-type-add').combobox({
            url: '${pageContext.request.contextPath}/code/getcaitype',
            method: 'GET',
            valueField: 'caiTypeId',
            textField: 'caiTypeName',
            prompt: '请选择彩种',
            onLoadSuccess: function () {
                var val = $(this).combobox('getData');
                if (val != null)
                    $(this).combobox("select", val[0].caiTypeId);
            },
            onSelect: function (data) {
                var url = '${pageContext.request.contextPath}/code/getcaicity?id=' + data.id;
                $('#lottery-city-add').combobox('reload', url);
            }
        });
        $('#lottery-city-add').combobox({
            method: 'GET',
            valueField: 'caiId',
            textField: 'caiName',
            prompt: '请选择省份',
            onLoadSuccess: function () {
                var val = $(this).combobox('getData');
                if (val != null)
                    $(this).combobox("select", val[0].caiId);
            }

        });
        // $('#lottery-issueno-add').combobox({
        //
        // });
        // $('#lottery-date-add').datebox({
        //     editable: false
        // });
        for (var i = 1; i <= 5; i++) {
            $('#number' + i).combobox({
                valueField: 'id',
                textField: 'value',
                data: codeNums
            });
        }
        $('#lottery-add').bind('click', function () {
            var typeId = $('#lottery-type-add').combobox('getValue');
            var caiId = $('#lottery-city-add').combobox('getValue');
            var issueNo = $('#lottery-issueno-add').val();
            var opencode = [];
            for (var i = 1; i <= 5; i++) {
                var code = $('#number' + i).combobox('getValue');
                opencode.push(code);
            }
            var commitTime = getFormatDate();
            console.log(commitTime);
            var params = {
                typeId: typeId,
                caiId: caiId,
                issueNo: issueNo,
                openCode: opencode.join(','),
                commitTime: commitTime
            };
            <%--$.post('${pageContext.request.contextPath}/code/addopencode', params, function (data) {--%>
            <%--    if (data.code === 10000) {--%>
            <%--        $.messager.alert('成功', '添加成功!');--%>
            <%--    } else {--%>
            <%--        $.messager.alert('错误', '添加失败!');--%>
            <%--    }--%>
            <%--}, 'json');--%>
            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/code/addopencode",
                data:JSON.stringify(params),
                dataType:"json",
                contentType: "application/json; charset=utf-8",//此处不能省略
                success:function(data){
                    if (data.code === 10000) {
                        $.messager.alert('成功', '添加成功!');
                    } else {
                        $.messager.alert('错误', '添加失败!');
                    }
                },
                error:function(data){
                    $.messager.alert('错误', '添加失败!');
                }
            });
        });
    })
</script>